<template>
  <div class='errorPublish-container'>

    <el-row :gutter="10" class="mb8 grid-content">
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete">删除</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="errorList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column prop="type" label="类别" align="center"></el-table-column>
      <el-table-column prop="id" label="Id" align="center"></el-table-column>
      <el-table-column prop="siteAlias" label="网站别名" align="center"></el-table-column>
      <el-table-column prop="message" label="错误信息" align="center" width="400" show-overflow-tooltip></el-table-column>
      <el-table-column prop="lastTime" label="最后发布时间" align="center" width="150"></el-table-column>
      <el-table-column prop="num" label="发布次数" align="center"></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>


<script>
import {
  errorReleaseList,
  errorReleaseDel,
  errorReleaseDelById,
} from "@/api/extendApplication/errorPublish";
import { getFirsClicktList } from "@/api/extendApplication/firstclick";
export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      //当前站点
      siteRow: null,

      siteList: [],
      //右侧表格
      errorList: [],
      dateRange: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
    };
  },

  components: {},

  computed: {},

  mounted() {
    this.getList();
  },

  methods: {
    getList() {
      this.loading = true;
      errorReleaseList(
        this.addDateRange(this.queryParams, this.dateRange)
      ).then((res) => {
        this.errorList = res.data.list;
        this.total = res.data.totalCount;
        this.loading = false;
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids.join(",");
      this.$confirm('是否确认删除Id为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return errorReleaseDelById({ ids });
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams = {
        pageNum: 1,
        siteId: this.siteRow.siteId,
      };
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>

<style scoped lang='scss'>
.errorPublish-container {
  display: flex;
  flex-direction: column;
}
</style> 